/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package facade;

import facade.AbstractFacade;
import remoteEntity.Role;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author viktor
 */
@Stateless
public class RoleFacade extends AbstractFacade<Role> {
    @PersistenceContext(unitName = "filecityeePU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public RoleFacade() {
        super(Role.class);
    }
    
    /*
     * Find a role by name
     */
    public Role find(String roleName){
        return (Role) em.createNamedQuery("Role.findByName").
                setParameter("name", roleName).
                getSingleResult();

    }

    public Role getGuestRole() {
        return find("Guest");
    }
    
    public Role getUserRole() {
        return find("User");
    }

    public Role getAdminRole() {
        return find("Administrator");
    }

    
}
